
class DictAPI:
    @staticmethod
    @micropython.native    
    def create_dict() -> dict:
        return {}

    @staticmethod
    @micropython.native    
    def get_value(dict_obj: dict, key) -> object:
        return dict_obj.get(key, None)

    @staticmethod
    @micropython.native    
    def set_value(dict_obj: dict, key, value) -> None:
        dict_obj[key] = value

    @staticmethod
    @micropython.native    
    def remove_key(dict_obj: dict, key) -> None:
        if key in dict_obj:
            del dict_obj[key]

    @staticmethod
    @micropython.native   
    def get_keys(dict_obj: dict) -> list:
        return list(dict_obj.keys())

    @staticmethod
    @micropython.native    
    def get_values(dict_obj: dict) -> list:
        return list(dict_obj.values())

class ListAPI:
    @staticmethod
    @micropython.native
    def create_list(*args) -> list:
        return list(args)

    @staticmethod
    @micropython.native
    def get_item(lst: list, index: int):
        try:
            return lst[index]
        except IndexError:
            return None

    @staticmethod
    @micropython.native
    def set_item(lst: list, index: int, value):
        try:
            lst[index] = value
        except IndexError:
            pass

    @staticmethod
    @micropython.native
    def get_length(lst: list) -> int:
        return len(lst)

    @staticmethod
    @micropython.native
    def append(lst: list, value):
        lst.append(value)

    @staticmethod
    @micropython.native
    def insert(lst: list, index: int, value):
        lst.insert(index, value)

    @staticmethod
    @micropython.native
    def remove(lst: list, value):
        try:
            lst.remove(value)
        except ValueError:
            pass

    @staticmethod
    @micropython.native
    def pop(lst: list, index: int = -1):
        try:
            return lst.pop(index)
        except IndexError:
            return None

    @staticmethod
    @micropython.native
    def extend(lst: list, iterable):
        lst.extend(iterable)

    @staticmethod
    @micropython.native
    def clear(lst: list):
        lst.clear()

class StringAPI:
    @staticmethod
    @micropython.native
    def create_string(value: str = "") -> str:
        return value

    @staticmethod
    @micropython.native
    def get_char(string: str, index: int) -> str:
        try:
            return string[index]
        except IndexError:
            return ""

    @staticmethod
    @micropython.native
    def set_char(string: str, index: int, char: str) -> str:
        try:
            return string[:index] + char + string[index + 1:]
        except IndexError:
            return string

    @staticmethod
    @micropython.native
    def get_length(string: str) -> int:
        return len(string)

    @staticmethod
    @micropython.native
    def concat(string1: str, string2: str) -> str:
        return string1 + string2

    @staticmethod
    @micropython.native
    def slice(string: str, start: int, stop: int = None, step: int = None) -> str:
        return string[slice(start, stop, step)]

    @staticmethod
    @micropython.native
    def contains(string: str, substring: str) -> bool:
        return substring in string

    @staticmethod
    @micropython.native
    def startswith(string: str, prefix: str) -> bool:
        return string.startswith(prefix)
    
    @staticmethod
    @micropython.native
    def split(string: str, prefix: str) -> bool:
        return string.split(prefix)

import os

class FileAPI:
    @staticmethod
    @micropython.native
    
    def open(filename, mode='r') -> object:
        try: return open(filename, mode)
        except: return None

    @staticmethod
    @micropython.native
    def read(file_obj, size=-1) -> bytes:
        return file_obj.read(size)

    @staticmethod
    @micropython.native
    def write(file_obj, data: bytes) -> int:
        return file_obj.write(data)

    @staticmethod
    @micropython.native
    def close(file_obj) -> None:
        file_obj.close()

    @staticmethod
    @micropython.native
    def remove(filename) -> None:
        os.remove(filename)

    @staticmethod
    @micropython.native
    def exists(filename) -> bool:
        return os.path.exists(filename)

import dish as module

if hasattr(module, "regDA_CD"):
    module.regDA_CD(DictAPI.create_dict)
    module.regDA_GVe(DictAPI.get_value)
    module.regDA_SV(DictAPI.set_value)
    module.regDA_GVs(DictAPI.get_values)
    module.regDA_RK(DictAPI.remove_key)
    module.regDA_GK(DictAPI.get_keys)

if hasattr(module, "regLA_CL"):
    module.regLA_CL(ListAPI.create_list)
    module.regLA_GI(ListAPI.get_item)
    module.regLA_SI(ListAPI.set_item)
    module.regLA_GLe(ListAPI.get_length)
    module.regLA_Ap(ListAPI.append)
    module.regLA_In(ListAPI.insert)
    module.regLA_Rm(ListAPI.remove)
    module.regLA_Po(ListAPI.pop)
    module.regLA_Ex(ListAPI.extend)
    module.regLA_Cr(ListAPI.clear)

if hasattr(module, "regSA_CS"):
    module.regSA_CS(StringAPI.create_string)
    module.regSA_GC(StringAPI.get_char)
    module.regSA_SC(StringAPI.set_char)
    module.regSA_GL(StringAPI.get_length)
    module.regSA_Cn(StringAPI.concat)
    module.regSA_Sl(StringAPI.slice)
    module.regSA_Ct(StringAPI.contains)
    module.regSA_Sw(StringAPI.startswith)
    module.regSA_Sp(StringAPI.split)

if hasattr(module, "regGA_Pr"):
    module.regGA_Pr(print)
    module.regGA_PrL(lambda t: print(t, end=''))
    module.regGA_In(input)
    module.regGA_Ln(len)
    module.regGA_Su(sum)

if hasattr(module, "regFA_Op"):
    module.regFA_Op(FileAPI.open)
    module.regFA_Rd(FileAPI.read)
    module.regFA_Wr(FileAPI.write)
    module.regFA_Cl(FileAPI.close)
    module.regFA_Rm(FileAPI.remove)
    module.regFA_Ex(FileAPI.exists)
    
if hasattr(module, "regFS_CD"):
    module.regFS_CD(os.chdir)
    module.regFS_GCD(os.getcwd)
    module.regFS_LD(os.listdir)
    module.regFS_MD(os.mkdir)

if hasattr(module, "regCA_INT"):
    module.regCA_INT(int)
    module.regCA_FLOAT(float)
    module.regCA_STR(str)
    module.regCA_BOOL(bool)

import time

st = time.ticks_us()
print(module.entry(None))
et = time.ticks_us()

print(et-st)

